
class App {
  // 补零
  formatNumber(n) {
    n = n.toString();
    return n[1] ? n : '0' + n;
  }

  // 格式时间
  formatTime(date) {
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();
    const weekArray = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
    const isToday = date.setHours(0, 0, 0, 0) == new Date().setHours(0, 0, 0, 0);
    return {
      hourly: [hour, minute].map(this.formatNumber).join(":"),
      daily: [month, day].map(this.formatNumber).join("-"),
      dailyToString: isToday ? "今天" : weekArray[date.getDay()]
    };
  }
}

export const app = new App();